<template>
  <div>
    <div class="topList">
      <router-link to="/appmain" class="topBtn">
        <i class="iconfont arrow-left">&#xe641;</i>
        <span class="allExam">综合考试</span>
      </router-link>
      <div class="examResult">
        <span class="examNum">{{getscore}}</span>分
      </div>
      <!--<div class="examTime">考试用时：0分34秒</div>-->
    </div>
    <div class="examend">
      <p class="examTitle" v-if="ispass">{{pass}}</p>
      <div class="examDesc">
        <p>本次考试共{{examnum}}题</p>
        <p>考试限定{{examtime}}分钟</p>
        <p>总分{{examtotal}}分，{{exampass}}分及格</p>
        <p>还剩{{leftnum}}次</p>
      </div>
      <div class="notpass">
        <p class="examStatu" v-if="isnotpassnotice">{{notpass}}</p>
        <el-button type="primary" v-if="isnotpass" @click="startexam">重新考试</el-button>
      </div>
    </div>
    <div class="bottombar">
      <router-link to="/appmain">
        <img src="../../assets/app/home.png" alt />
      </router-link>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      getscore: null,
      pass: "恭喜你已通过岗前培训综合考试！",
      notpass: "很遗憾！请重新参加考试！",
      examnum: null,
      examtime: null,
      examtotal: null,
      exampass: null,
      student: null,
      leftnum: null,

      ispass: true,
      isnotpass: true,
      isnotpassnotice: true
    };
  },
  //初始化信息加载
  mounted: function() {
    this.student = JSON.parse(localStorage.getItem("studentinfo"));
    let examinfo = JSON.parse(localStorage.getItem("examinfo"));
    this.examnum =
      examinfo.jduge_num + examinfo.selection_num + examinfo.many_num;
    this.examtime = examinfo.examtime;
    this.examtotal = examinfo.examtotal;
    this.exampass = examinfo.examave;
    this.examid = localStorage.getItem("examid");
    this.$axios
      .get("/ExamStart/getscore", {//获取学员分数
        params: { st_id: this.student.St_id, examid: this.examid }
      })
      .then(res => {

        this.getscore = res.data.score;
        this.leftnum = res.data.leftnum;
        if (parseInt(res.data.score) >= parseInt(this.exampass)) {//判断是否通过
          this.ispass = true;
          this.isnotpass = false;
          this.isnotpassnotice = false;
        } else {
          if (res.data.leftnum == 0) {//没有考试次数了
            this.isnotpass = false;
            this.isnotpassnotice = true;
            this.notpass = "很遗憾，你的考试次数已用完";
          } else {
            this.isnotpass = true;
            this.isnotpassnotice = true;
          }
          this.ispass = false;
        }
      });
  },

  methods: {
    startexam() {
      localStorage.setItem("order", 1);
      this.$axios
        .get("/ExamStart/startexam", {
          params: { st_id: this.student.St_id }
        })
        .then(res => {
          let examid = res.data;
          localStorage.setItem("examid", examid);
          this.$router.push({ path: "/exampage" });
            let date =new Date();
               localStorage.setItem("starttime", date.toString());//考试开始时间
        });
    }
  }
};
</script>

<style scoped>
@font-face {
  font-family: "iconfont"; /* project id 1514769 */
  src: url("//at.alicdn.com/t/font_1514769_4qk754zzrki.eot");
  src: url("//at.alicdn.com/t/font_1514769_4qk754zzrki.eot?#iefix")
      format("embedded-opentype"),
    url("//at.alicdn.com/t/font_1514769_4qk754zzrki.woff2") format("woff2"),
    url("//at.alicdn.com/t/font_1514769_4qk754zzrki.woff") format("woff"),
    url("//at.alicdn.com/t/font_1514769_4qk754zzrki.ttf") format("truetype"),
    url("//at.alicdn.com/t/font_1514769_4qk754zzrki.svg#iconfont") format("svg");
}
.notpass {
  text-align: center;
}

.iconfont {
  font-family: "iconfont" !important;
  font-size: 25px;
  font-style: normal;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  vertical-align: sub;
}
.topList {
  height: 13rem;
  width: 100%;
  line-height: 3rem;
  /* border:1px solid red; */
  text-align: center;
  font-size: 18px;
  background-image: linear-gradient(135deg, #0396ff 10%, #abdcff 100%);
}
.topBtn {
  text-decoration: none;
  color: white;
  display: inline-block;
  width: 100%;
}
.allExam {
  margin-left: -2rem;
}
.arrow-left {
  float: left;
}
p {
  margin: 0;
  padding: 0;
}
.examResult {
  height: 7rem;
  line-height: 7rem;
  border-top: 1px solid;
  color: white;
  font-size: 20px;
}
.examNum {
  font-size: 80px;
}
.examTime {
  color: white;
  font-size: 18px;
}
.examTitle {
  text-align: center;
  font-size: 18px;
  margin: 25px 0;
  font-weight: 600;
  color: green;
}

.examDesc {
  margin: 0 auto;
  width: 90%;
  /* border: 1px solid red; */
  font-size: 13px;
  text-align: center;
  color: #a0a0a0;
}
.examStatu {
  color: red;
  text-align: center;
  margin: 25px 0;
  font-size: 20px;
}

.bottombar {
  position: fixed;
  z-index: 900;
  bottom: 0;
  left: 0;
  right: 0;
  margin: auto;
  border: 1px solid white;
  height: 50px;
  text-align: center;
  background: rgb(36, 164, 255);
  box-shadow: 0 1px 0 0 rgba(255, 255, 255, 0.1) inset;
}
.bottombar img {
  background: white;
  padding: 10px;
  border-radius: 50%;
  position: relative;
  /* top: -20px; */
  text-shadow: 0 1px rgba(0, 0, 0, 0.3);
  /* border: 5px solid gray; */
}
</style>
